package ar.edu.unicen.exa.isistan.archassis.util;

import java.util.Collection;
import java.util.List;

import ar.edu.unicen.exa.isistan.archassis.actions.IAction;
import ar.edu.unicen.exa.isistan.archassis.ia.api.db.JavaClass;
import ar.edu.unicen.exa.isistan.archassis.ia.seed.VariableSeed;
import ar.edu.unicen.exa.isistan.archassis.metadata.ClassResolver;

public class AllActionPrint implements IActionPrint {

	@Override
	public String toString(List<IAction> list) {
		return getActionListText(list) + "\n\n";// + getClassImports();
	}

	private static String getActionListText(List<IAction> list) {
		if (list == null) {
			return "no hay acciones";
		}
		StringBuffer result = new StringBuffer();
		
		for (IAction action : list) {
			result.append(" ========================================================================\n");
			result.append(" ").append(action.getClass().getCanonicalName()).append("\n");
			result.append(" ========================================================================\n");
			result.append(action.getDescription()).append("\n");
			
			for(String key : action.getMetadata().keySet()) {
				String value = action.getMetadata().get(key);
				result.append("\t").append(key).append("=").append(value).append("\n");
			}
			result.append("\n");
		}
		return result.toString();
	}
	
//	private static String getClassImports() {
//		//Collection<JavaClass> javaClassList = ClassResolver.getInstance().getClassMetadataV1();
//		StringBuffer result = new StringBuffer();
//		
//		for (JavaClass javaClass : javaClassList) {
//			//List<String> importClassList = classData.getFieldTypes();
//			result.append(" ========================================================================\n");
//			result.append(javaClass.getNombre()).append("\n");
//			
//			result.append("IMPORTA:\n");
//			//result.append(listToString(javaClass.getImports()));
//			
//			result.append("USA:\n");
//			//result.append(listVariablesToString(javaClass.getVariables()));
//			
//			result.append("\n");
//		}
//		return result.toString();
//	}
	
	
	public static String listVariablesToString(List<VariableSeed> variables) {
		StringBuffer result = new StringBuffer();
		for (VariableSeed javaVariable : variables) {
			result.append("\t").append(javaVariable.getType()).append("\n");
		}
		return result.toString();
	}

	public static String listToString(List<String> list) {
		StringBuffer result = new StringBuffer();
		for (String item : list) {
			result.append("\t").append(item).append("\n");
		}
		return result.toString();
	}
}
